//
//  LDJ_StractionCell.m
//  Pianke
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "LDJ_StractionCell.h"

@implementation LDJ_StractionCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)createSubView{
    
    
    //类型
    self.type = [[UILabel alloc]init];
    self.type.text = @"心理.Psychology";
    self.type.font = [UIFont systemFontOfSize:12];
    self.type.textColor = [UIColor colorWithRed:0.47 green:0.47 blue:0.47 alpha:1];
    [self.contentView addSubview:self.type];
    
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(150 * EACH_WIDTH, 15 * EACH_HEIGHT));
        make.left.mas_equalTo(20 * EACH_WIDTH);
        make.top.mas_equalTo(10 * EACH_HEIGHT);
        
    }];
    
    
    
    //取中间部分放入框中
    //剪裁边缘
    self.headerImgView.clipsToBounds = YES;
    self.headerImgView.tag = 1001;
    //图片
    self.headerImgView = [[UIImageView alloc]init];
    self.headerImgView.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.headerImgView];
    self.headerImgView.userInteractionEnabled = YES;
    [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40 * EACH_WIDTH, 140 * EACH_HEIGHT));
        make.left.equalTo(self.type);
        make.top.mas_equalTo(self.type.mas_bottom).offset(20 * EACH_HEIGHT);
        
    }];
    
    // 小图
    self.smallImgView = [[UIImageView alloc]init];
    self.smallImgView.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.smallImgView];
    self.smallImgView.tag = 1002;
    self.smallImgView.userInteractionEnabled = YES;
    [self.smallImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 45 ) / 2, 140 * EACH_HEIGHT));
        make.left.equalTo(self.type);
        make.top.mas_equalTo(self.headerImgView.mas_bottom).offset(5 * EACH_HEIGHT);
        
    }];
    
    self.brotherImgView = [[UIImageView alloc]init];
    self.brotherImgView.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.brotherImgView];
    self.brotherImgView.tag = 1003;
    self.brotherImgView.userInteractionEnabled = YES;
    [self.brotherImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 45 ) / 2, 140 * EACH_HEIGHT));
        make.left.mas_equalTo(self.smallImgView.mas_right).offset(5 * EACH_HEIGHT);
        make.top.equalTo(self.smallImgView);
        
    }];
    
    
    
    self.imgCount = [[UILabel alloc]init];
    self.imgCount.textAlignment = NSTextAlignmentCenter;
    self.imgCount.contentMode = UIViewContentModeCenter;
    self.imgCount.backgroundColor = [UIColor grayColor];
    self.imgCount.alpha = 0.5;
    self.imgCount.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.imgCount];
    [self.imgCount mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.bottom.equalTo(self.brotherImgView);
        make.size.mas_equalTo(CGSizeMake(20 * EACH_WIDTH, 20 * EACH_HEIGHT));
        
    }];
    
    
    
    
    
    
    //标题
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont systemFontOfSize:20 * EACH_HEIGHT];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.contentMode = UIViewContentModeCenter;
    [self.titleLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.smallImgView);
        make.top.mas_equalTo(self.brotherImgView.mas_bottom).offset(20 * EACH_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 80 * EACH_WIDTH, 40 * EACH_HEIGHT));
        
    }];
    
    
    //内容
    self.content = [[UILabel alloc]init];
    self.content.font = [UIFont systemFontOfSize:16 * EACH_HEIGHT];
    self.content.textColor = [UIColor colorWithRed:0.47 green:0.47 blue:0.47 alpha:1];
    self.content.numberOfLines = 3;
    [self.contentView addSubview:self.content];
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10 * EACH_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40 * EACH_WIDTH, 60 * EACH_HEIGHT));
        
    }];
    
    //心形图
    self.heartButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.heartButton  setImage:[UIImage imageNamed:@"iconfont-xinxihuan00-2.png"] forState:UIControlStateNormal];
    [self.contentView addSubview: self.heartButton];
    [self.heartButton addTarget:self action:@selector(heartButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.heartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(15 * EACH_WIDTH, 15 * EACH_HEIGHT));
        make.top.mas_equalTo(self.content.mas_bottom).offset(30 * EACH_HEIGHT);
        make.right.mas_equalTo(-60);
        
        
    }];
    
    
    //赞数
    self.zanLabel = [[UILabel alloc]init];
    self.zanLabel.font = [UIFont systemFontOfSize:EACH_HEIGHT * 12];
    self.zanLabel.textColor = [UIColor colorWithRed:0.47 green:0.47 blue:0.47 alpha:1];
    self.zanLabel.text = @"311";
    [self.contentView addSubview:self.zanLabel];
    [self.zanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(50 * EACH_WIDTH, 15 * EACH_HEIGHT));
        make.left.mas_equalTo(self.heartButton.mas_right).offset(10);
        make.top.equalTo(self.heartButton);
        
    }];
    
#pragma mark  轻拍手势
    //轻拍
    UITapGestureRecognizer *headerTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.headerImgView addGestureRecognizer:headerTap];
    
    //轻拍
    UITapGestureRecognizer *smallTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.smallImgView addGestureRecognizer:smallTap];
    
    //轻拍
    UITapGestureRecognizer *brotherTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.brotherImgView addGestureRecognizer:brotherTap];
    
    
}

#pragma mark - 轻拍手势
-(void)tapAction:(UITapGestureRecognizer *)tap{

    
    
    [self.stractionCellDelegate presentToViewController:tap.view.tag ImgArray:self.allImgArray];
    
    
    
}

-(void)setIllModel:(LDJ_HomeModel *)illModel{
    
    _illModel = illModel;
    NSString *s = [NSString stringWithFormat:@"%@", illModel.imgtotal];
    self.imgCount.text = s;
    NSString *str = [NSString stringWithFormat:@"%@•%@",illModel.name,illModel.enname];
    self.type.text = str;
    self.titleLabel.text = illModel.title;
    self.content.text = illModel.content;
    //    self.name.text =
    NSString *string = [NSString stringWithFormat:@"%@", illModel.like];
    self.zanLabel.text = string;
    
    [self.headerImgView sd_setImageWithURL:illModel.coverimg placeholderImage:[UIImage imageNamed:@"u=1640821638,783268506&fm=21&gp=0.jpg"]];
    for (int i = 0; i < illModel.imglist.count; i++) {
        
        if (i == 1) {
            
            [self.smallImgView sd_setImageWithURL:[[illModel.imglist objectAtIndex:i] objectForKey:@"imgurl"] placeholderImage:[UIImage imageNamed:@"u=2274944626,3260057393&fm=21&gp=0.jpg"]];
        }
        if (i == 2) {
            
            [self.brotherImgView sd_setImageWithURL:[[illModel.imglist objectAtIndex:i] objectForKey:@"imgurl"] placeholderImage:[UIImage imageNamed:@"u=2274944626,3260057393&fm=21&gp=0.jpg"]];
        }
    }
    
    self.allImgArray = [NSMutableArray array];
    //把图片地址取出来放数组里
    for (NSMutableDictionary *dic in self.illModel.imglist) {
        [self.allImgArray addObject:[dic objectForKey: @"imgurl"]];
    }
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
